package com.lmmob.autotest.uitest.assertions;

import java.util.Arrays;
import java.util.Map;

import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

public class MapAssert {
    public static void assertContains(Map<String, Object> actual, Map<String, Object> expected) {
        assertNotNull(actual);
        assertNotNull(expected);
        for (String key : expected.keySet()) {
            Object expectValue = expected.get(key);
            if (expectValue != null) {
                assertThat(Arrays.asList(actual.entrySet().toArray(new String[]{})), hasItem(key));
                Object actualValue = actual.get(key);
                assertThat(actualValue, is(expectValue));
            } else {
                if (actual.containsKey(key)) {
                    assertNull(actual.get(key));
                }
            }
        }
    }
}
